package com.my.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.my.entity.UserMonitor;
import com.my.service.AttendanceLogService;
import com.my.service.UserMonitorService;
import com.my.service.UserService;
import com.my.util.Rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api")
@CrossOrigin
public class AttendanceLogApiController {

    @Autowired
    private AttendanceLogService service;

    @Autowired
    private UserMonitorService monitorService;

    @Autowired
    private UserService uService;

    @GetMapping("AttendanceLog")
    public Rest getAttendanceLog(Long userId, Long classId) {
        if(userId != null) {
            UserMonitor monitor = monitorService.getOne(new QueryWrapper<UserMonitor>().eq("user_id", userId).eq("type", 1));
            if(monitor != null) {
                userId = null;
                classId = monitor.getGradeClassId();
            }
        }
        Integer userType = null;
        if(userId != null) {
            userType = uService.getById(userId).getType();
        }
        return Rest.ok().setData("list", service.getApiList(userId, userType, classId));
    }

}
